package com.ultrasoft.farmasoft.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Menu;

@Repository(value = "menuDao")
@Transactional(readOnly = false)
public class MenuDaoImpl implements MenuDao {
	private EntityManager em = null;
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		this.em = em;
	} 
	
	@SuppressWarnings("unchecked")
	public List<Menu> getMenuList() {
		return em.createNamedQuery("Menu.findAll").getResultList();
	}
	public Menu findByMenuId(short menuId) {
		Menu res=null;
		try {
			res=em.find(Menu.class,menuId);
		} catch (Exception e) {
			// TODO: handle exception
		}
    	return res;
	}

	public void update(Menu menu) {
		em.merge(menu);
	}
	public void remove(Menu menu) {
		em.remove(em.getReference(Menu.class,menu.getMenuId()));
	}
	public void add(Menu menu) {
		em.persist(menu);
	}
}
